//
//  SLUser.swift
//  0319iOSweiboDemo
//
//  Created by Tang on 16/3/25.
//  Copyright © 2016年 大天朝. All rights reserved.
//

import UIKit

class SLUser: NSObject {
    
    /**
     *  用户UID
     */
    var id: Int64 = 0
    
    /**
     *  用户头像地址
     */
    var profile_image_url: String?
    
    /**
     *  用户昵称
     */
    var screen_name: String?
    
    /**
    *  会员等级  1 - 6 . 给别人用不方便.需要做判断
    */
    var mbrank: Int = 0 {
        didSet {
            //当kvc给mbrank赋值的时候.我们给mbrankImage赋值
            if mbrank > 0 && mbrank <= 6 {
                memberImage = UIImage(named: "common_icon_membership_level\(mbrank)")
            } else {
                memberImage = nil
            }

        }
    }
    //memberView会员等级对应的图片
    var memberImage: UIImage?

    /**
     *  认证类型
     */
    //没有是-1
    var verified_type: Int = -1 {
        didSet {
            switch verified_type {
                case 0:
                    verfiedImage = UIImage(named: "avatar_vip")
                case 2,3,5:
                    verfiedImage = UIImage(named: "avatar_enterprise_vip")
                case 220:
                    verfiedImage = UIImage(named: "avatar_grassroot")
                default:
                    verfiedImage = nil
                }
            
          }
    }
    
    var verfiedImage: UIImage?
    
    
    //字典转模型
    init(dict: [String: AnyObject]) {
        super.init() // 创建对象
        
        //KVC赋值
        setValuesForKeysWithDictionary(dict)
    }
    
    //字典的key在模型中找不到对应的属性
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    //打印对象
    override var description: String {
        //只读属性
        get { //只读计算性属性
            let keys = ["id", "profile_image_url", "screen_name", "mbrank" ,"verified_type"]
            
            return "\n \t:微博模型: \(dictionaryWithValuesForKeys(keys).description)"
        }
    }
    
    
}
